package com.neutech.view;
import com.neutech.dao.FoodDAO;
import com.neutech.dao.impl.FoodDAOImpl;
import com.neutech.entity.Food;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import static com.neutech.constant.Constant.input;
import static com.neutech.view.AdminView.showMeau;


public class FoodView {
    private final static FoodDAO foodDAO = new FoodDAOImpl();
    private final static BusinessView businessview = new BusinessView();
    private static String foodNameDate;

    public static void showFoodAll() {
        List<Food> foodList = new ArrayList<>();
        foodList = foodDAO.showFoodAll();
        if (foodList.size() == 0) {
            System.out.println("没有食物数据");
            BusinessView.showMeau();
        } else {
            for (Food food : foodList) {
                System.out.println(food);
            }
        }
        BusinessView.showMeau();
    }

    public static void insertFood(){
        System.out.println("食品名称");
        String foodName=input.next();
        System.out.println("食品介绍");
        String foodExplain=input.next();
        System.out.println("食品价格");
        BigDecimal foodPrice=input.nextBigDecimal();
        System.out.println("所属商家编号");
        int businessId=input.nextInt();
        Food food=new Food();
        food.setFoodPrice(foodPrice);
        food.setFoodName(foodName);
        food.setFoodExplain(foodExplain);
        food.setBusinessId(businessId);
        foodDAO.insert(food);
        System.out.println("增加成功");
        showMeau();
    }
    public static void modifyFood() {
        System.out.println("请输入食物名");
        String foodNameDate = input.next();
        Food food = (Food) foodDAO.showFoodAll();
        if (food.getFoodId() == null) {
            System.out.println("无此食物");
        } else {
            System.out.println("食品名称");
            String foodName = input.next();
            System.out.println("食品介绍");
            String foodExplain = input.next();
            System.out.println("食品价格");
            BigDecimal foodPrice = input.nextBigDecimal();
            System.out.println("所属商家编号");
            int businessId = input.nextInt();
            food.setFoodPrice(foodPrice);
            food.setFoodName(foodName);
            food.setFoodExplain(foodExplain);
            food.setBusinessId(businessId);
            foodDAO.update(food);
            System.out.println("修改成功");
            showMeau();
        }
    }
    public static void putFood() {
        System.out.println("请输入要删除的食品名称");
        String foodName = input.next();
        Food food = foodDAO.selectFoodName(foodName);
        if (food.getFoodId() == null) {
            System.out.println("没有此食品");
            showMeau();
        } else {
            food.setFoodId(food.getFoodId());
            foodDAO.delete(food);
            System.out.println("删除成功");
            showMeau();
        }
    }
}
